package com.yfree.utils.net;

import org.json.JSONObject;

import java.io.Serializable;

public class YJsonKV implements Serializable {
    private JSONObject jsonObject;

    public YJsonKV() {
        jsonObject = new JSONObject();
    }

    public YJsonKV put(String name, Object value) {
        try {
            /*jsonObject.put(name,value.toString().replace("{", "（").replace("}", "）")
                            .replace("[", "（").replace("]", "）")
							.replace("\"", "'").replace(":", "："));*/
            if (value != null) {
                jsonObject.put(name, value.toString());
            }
        } catch (Exception ignored) {
        }
        return this;
    }

    public Object get(String name) {
        try {
            return jsonObject.get(name);
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public String toString() {
        if (jsonObject.length() <= 0) {
            return "";
        }
        return jsonObject.toString();
    }
}
